package com.example.transit.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.transit.R;
import com.example.transit.bean.CarlineInfo;
import com.example.transit.bean.StationInfo;
import com.example.transit.utils.SPUtils;

import java.util.List;

public class SearchListviewAdapter extends MyBaseAdapter<CarlineInfo> {
    private List<List<StationInfo>> mList;
    private Context context;
    public SearchListviewAdapter(List<List<StationInfo>> mList,Context context) {
        super(context);
        this.context=context;
        this.mList=mList;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
       ViewHolder holder=null;
       if (convertView==null){
           convertView=inflater.inflate(R.layout.adapter_search_listview, null);
           holder=new ViewHolder(convertView);
           convertView.setTag(holder);
       }else {
           holder= (ViewHolder) convertView.getTag();
       }
        List<StationInfo> stationInfoList = mList.get(position);
      //  Log.d("may", "stationInfoList: " + stationInfoList.size());
        if(stationInfoList.size()!=0){
        holder.car_num.setText(stationInfoList.get(0).getLineNum());
        holder.start_end_loc.setText(stationInfoList.get(0).getStationName()+"--"+stationInfoList.get(stationInfoList.size()-1).getStationName());
        }
        return convertView;
    }
    class ViewHolder{
      public  TextView car_num;
      public TextView start_end_loc;
      public ViewHolder(View view){
          car_num=view.findViewById(R.id.seach_listview_carNum);
          start_end_loc=view.findViewById(R.id.seach_listview_star_end);
      }
    }
}
